package org.bm.st.win;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class DesktopCapture extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3616241828548949113L;

	
	// JButton confirm;
    // BufferedImage desktopImg;
    SimpleTray simpleTray;
    boolean iconed = false;

    public DesktopCapture() {
        super("EasyCapture");
        init();
        // 当点击"-"最小化按钮时，系统会最小化到托盘
        addWindowListener(new WindowAdapter() {
            public void windowIconified(WindowEvent e) {
                iconed = true;
                setVisible(false);
            }

            // 当点击"X"关闭窗口按钮时，会询问用户是否要最小化到托盘
            // 是，表示最小化到托盘，否，表示退出
            public void windowClosing(WindowEvent e) {
                int option = JOptionPane.showConfirmDialog(DesktopCapture.this,
                        "是否最小化到托盘?", "提示:", JOptionPane.YES_NO_OPTION);
                if (option == JOptionPane.YES_OPTION) {
                    iconed = true;
                    setVisible(false);
                } else {
                    System.exit(0);
                }
            }
        });
        pack();
        setSize(350, 230);
        setLocation(500, 300);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setResizable(true);
        setVisible(true);
    }

    void init() {

        simpleTray = new SimpleTray(DesktopCapture.this);
    }

    // 截图
    public void capture() {

    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            
            new DesktopCapture();
            
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
	
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub

	}

}
